package com.jcfk.system.controller;

import cn.hutool.core.bean.BeanUtil;
import com.jcfk.common.business.controller.BaseController;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.system.domain.dto.RefUserRoleMappingDTO;
import com.jcfk.system.domain.dto.UserAndRoleDTO;
import com.jcfk.system.domain.query.RefUserRoleMappingQuery;
import com.jcfk.system.service.RefUserRoleMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户角色关联
 */
@RestController
@RequestMapping("/refUserRole")
public class RefUserRoleController extends BaseController {
    @Autowired
    private RefUserRoleMappingService refUserRoleService;

    @PostMapping("getList")
    public RetResult<List<RefUserRoleMappingDTO>> getList(@RequestBody RefUserRoleMappingQuery query) {
        List<RefUserRoleMappingDTO> list = refUserRoleService.getList(query);
        return RetResult.ok(list);
    }

    @RequestLogHeader(modular = "用户角色管理", businessType = "保存")
    @PostMapping("saveList")
    public RetResult<?> saveList(@RequestBody UserAndRoleDTO userAndRoleDTO) {
        refUserRoleService.saveList(userAndRoleDTO.getUserId(), userAndRoleDTO.getRoleIds());
        return RetResult.ok();
    }
}
